package com.huawei.appgallery.purchasehistory.ui.activity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import androidx.annotation.Nullable;
import com.huawei.appgallery.foundation.ui.framework.activity.BaseActivity;
import com.huawei.appgallery.foundation.ui.framework.uikit.ContractFragment;
import com.huawei.appgallery.foundation.ui.framework.widget.FixViewPager;
import com.huawei.appgallery.purchasehistory.impl.PurchaseHistoryManager;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import java.util.ArrayList;
import java.util.List;
import o.azc;
import o.cgv;
import o.cjo;
import o.csp;
import o.cst.a;
import o.csu;
import o.ctk;
import o.ctn;
import o.cto;
import o.dof;
import o.ContentManager;
import o.CollectCheck;
import o.ActivityUtil;
import o.ll;
import org.jetbrains.annotations.NotNull;

public abstract class PurchaseMenuActivity<T extends cjo> extends BaseActivity<T> implements cto {
    private static final String ॱˊ = (ContentManager.getInstant().getContext().getPackageName() + ".appzone_trace_change_broadcast");
    protected View ʻॱ;
    protected Menu ʽॱ;
    protected final BroadcastReceiver ʾ = new SafeBroadcastReceiver(this) {
        String ˋ;
        boolean ˎ = false;
        final /* synthetic */ PurchaseMenuActivity ˏ;
        String ॱ;

        {
            this.ˏ = r2;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            String action = intent.getAction();
            if (!dof.ˎ(PurchaseMenuActivity.ॱˊ, action)) {
                if (intent.getDataString() != null && intent.getDataString().length() >= 9) {
                    String substring = intent.getDataString().substring(8);
                    if (CollectCheck.isEmpty(this.ˏ.ॱˎ)) {
                        csp.ˏ.ˋ("PurchaseMenuActivity", "list.size = 0");
                        return;
                    } else if (!dof.ॱ(this.ˋ) && dof.ˎ(this.ˋ, action) && !dof.ॱ(this.ॱ) && dof.ˎ(this.ॱ, substring) && this.ˎ) {
                        csp.ˏ.ˋ("PurchaseMenuActivity", "filter same action");
                        this.ˋ = "";
                        this.ˎ = false;
                        return;
                    } else {
                        this.ˋ = action;
                        this.ॱ = substring;
                    }
                } else {
                    return;
                }
            }
            try {
                for (ctn ˎ : this.ˏ.ॱˎ) {
                    ˎ.ˎ(action);
                }
                this.ˎ = true;
            } catch (Throwable e) {
                csp.ˏ.ˊ("PurchaseMenuActivity", "APPZONE_TRACE_CHANGE_BROADCAST error!", e);
            }
        }
    };
    protected FixViewPager mFixViewPager;
    protected final List<ctn> ॱˎ = new ArrayList();
    protected View ᐝॱ;

    protected abstract void ah_();

    protected abstract void ʼॱ();

    public abstract void ˎ(int i);

    protected abstract int ᐝ();

    protected abstract void ᐝॱ();

    public void onCreate(@Nullable Bundle bundle) {
        super.onCreate(bundle);
        ll.ˏ(getApplicationContext()).ˏ(this.ʾ, new IntentFilter(ॱˊ));
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("android.intent.action.PACKAGE_ADDED");
        intentFilter.addAction("android.intent.action.PACKAGE_REMOVED");
        intentFilter.addDataScheme(HiAnalyticsConstant.BI_KEY_PACKAGE);
        ActivityUtil.registerReceiver(this, intentFilter, this.ʾ);
    }

    public void onDestroy() {
        super.onDestroy();
        ll.ˏ(getApplicationContext()).ˋ(this.ʾ);
        ActivityUtil.unregisterReceiver((Context) this, this.ʾ);
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        ˏ(menu);
        ˊˋ();
        return true;
    }

    protected void ˏ(Menu menu) {
        if (azc.ˎ().ॱ() >= 21) {
            if (this.ᐝॱ != null) {
                this.ᐝॱ.setVisibility(8);
            }
            if (menu != null) {
                menu.clear();
                getMenuInflater().inflate(ᐝ(), menu);
                this.ʽॱ = menu;
            }
        }
    }

    public void ˊˋ() {
        if (isFinishing() || this.mFixViewPager == null) {
            ˊ(false);
        } else {
            ˎ(this.mFixViewPager.getCurrentItem());
        }
    }

    protected void ˊ(boolean z) {
        int i = 0;
        if (z) {
            cgv.ˋ(this, a.ॱ, a.ˊ);
        } else {
            cgv.ˋ(this, a.ॱ, a.ʼ);
        }
        if (azc.ˎ().ॱ() < 21) {
            ˏ(z);
        } else if (this.ʽॱ == null) {
        } else {
            if (z) {
                while (i < this.ʽॱ.size()) {
                    this.ʽॱ.getItem(i).setVisible(true);
                    this.ʽॱ.getItem(i).setEnabled(true);
                    i++;
                }
                ah_();
                return;
            }
            for (int i2 = 0; i2 < this.ʽॱ.size(); i2++) {
                this.ʽॱ.getItem(i2).setVisible(false);
                this.ʽॱ.getItem(i2).setEnabled(false);
            }
        }
    }

    private void ˏ(boolean z) {
        if (this.ᐝॱ != null && this.ʻॱ != null) {
            if (!z) {
                this.ᐝॱ.setVisibility(8);
                this.ʻॱ.setVisibility(8);
            } else if (getApplicationContext().getResources().getConfiguration().orientation == 2) {
                this.ᐝॱ.setVisibility(8);
                this.ʻॱ.setVisibility(0);
                ᐝॱ();
            } else {
                this.ᐝॱ.setVisibility(0);
                this.ʻॱ.setVisibility(8);
                ʼॱ();
            }
        }
    }

    public void onConfigurationChanged(@NotNull Configuration configuration) {
        super.onConfigurationChanged(configuration);
        ˊˋ();
    }

    public void ˋ(ContractFragment contractFragment) {
        if (contractFragment instanceof ctk) {
            ˊ(((ctk) contractFragment).י());
            return;
        }
        ˊ(false);
        csp.ˏ.ˋ("PurchaseMenuActivity", "fragment not instanceof HasDataInterface");
    }

    public void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        bundle.putString("purchase_history_helper_class_name", PurchaseHistoryManager.getHelper().getClass().getName());
    }

    public void onRestoreInstanceState(Bundle bundle) {
        Throwable e;
        super.onRestoreInstanceState(bundle);
        if (bundle != null) {
            String string = bundle.getString("purchase_history_helper_class_name");
            if (!dof.ॱ(string) && !string.equals(PurchaseHistoryManager.getHelper().getClass().getName())) {
                try {
                    Object newInstance = Class.forName(string).newInstance();
                    if (newInstance instanceof csu) {
                        PurchaseHistoryManager.setHelper((csu) newInstance);
                    }
                } catch (IllegalAccessException e2) {
                    e = e2;
                    csp.ˏ.ˊ("PurchaseMenuActivity", "parse json error", e);
                } catch (InstantiationException e3) {
                    e = e3;
                    csp.ˏ.ˊ("PurchaseMenuActivity", "parse json error", e);
                } catch (ClassNotFoundException e4) {
                    e = e4;
                    csp.ˏ.ˊ("PurchaseMenuActivity", "parse json error", e);
                }
            }
        }
    }
}
